/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ErrorGenerators.java
 *
 * Created on 22-mar-2010, 11.51.15
 */

package ch.epfl.dslab.conferrng.wizard;

import ch.epfl.dslab.conferrng.arugula.ErrorGenerator;
import ch.epfl.dslab.conferrng.engine.FaultInjectionPlan;
import java.awt.Component;
import org.netbeans.spi.wizard.Wizard;
import org.netbeans.spi.wizard.WizardPage;
import org.netbeans.spi.wizard.WizardPanelNavResult;

/**
 *
 * @author lokeller
 */
public class ErrorGenerators extends WizardPage {

    private FaultInjectionPlan faultInjectionPlan;
    public static final String PROP_FAULTINJECTIONPLAN = "faultInjectionPlan";

    public void setFaultInjectionPlan(FaultInjectionPlan faultInjectionPlan) {
        System.err.println("***********************"+faultInjectionPlan);
        this.faultInjectionPlan = faultInjectionPlan;

        arugulaCodePanel.setPlan(faultInjectionPlan);
        arugulaProjectPanel1.setPlan(faultInjectionPlan);
        arugulaToolbar1.setPlan(faultInjectionPlan);        

    }

    public static String getDescription() {
        return "Configure Error Generators";
    }

    /** Creates new form ErrorGenerators */
    public ErrorGenerators() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        arugulaToolbar1 = new ch.epfl.dslab.conferrng.wizard.ArugulaToolbar();
        arugulaProjectPanel1 = new ch.epfl.dslab.conferrng.wizard.ArugulaProjectPanel();
        jPanel2 = new javax.swing.JPanel();
        arugulaCodePanel = new ch.epfl.dslab.conferrng.wizard.ArugulaCodePanel();

        setLayout(new java.awt.BorderLayout());

        jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);

        jPanel1.setLayout(new java.awt.BorderLayout());

        arugulaToolbar1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2), javax.swing.BorderFactory.createLineBorder(javax.swing.UIManager.getDefaults().getColor("Button.focus"))));
        jPanel1.add(arugulaToolbar1, java.awt.BorderLayout.EAST);
        jPanel1.add(arugulaProjectPanel1, java.awt.BorderLayout.CENTER);

        jTabbedPane1.addTab("Visual editor", jPanel1);

        jPanel2.setLayout(new java.awt.BorderLayout());
        jPanel2.add(arugulaCodePanel, java.awt.BorderLayout.CENTER);

        jTabbedPane1.addTab("Code", jPanel2);

        add(jTabbedPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public WizardPanelNavResult allowNext(java.lang.String stepName, java.util.Map settings, Wizard wizard) {
        faultInjectionPlan.computeConfigurationWithErrors();
        return WizardPanelNavResult.PROCEED;
    }

    @Override
    protected String validateContents(Component component, Object event) {
        for ( ErrorGenerator e : faultInjectionPlan.getErrorGenerators()) {
            if ( e.getErrors().size() > 0 ) return "Please fix the errors in the error generators";
        }
        return null;
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ch.epfl.dslab.conferrng.wizard.ArugulaCodePanel arugulaCodePanel;
    private ch.epfl.dslab.conferrng.wizard.ArugulaProjectPanel arugulaProjectPanel1;
    private ch.epfl.dslab.conferrng.wizard.ArugulaToolbar arugulaToolbar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

}
